package com.pda.gongpin.ui.shipments;

import android.widget.Button;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.pda.gongpin.R;
import com.pda.gongpin.adapter.ShipmentsStaticsAdapter;
import com.pda.gongpin.bean.ShipmentsStaticsBean;
import com.pda.gongpin.bean.request.DeliveryNoRequest;
import com.pda.gongpin.contract.ShipmentsStaticsContract;
import com.pda.gongpin.dialog.AffirmDialog;
import com.pda.gongpin.presenter.ShipmentsStaticsPresenter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.wangshen.base.ui.mvp.base.ui.BaseMvpFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class ShipmentsStaticsFragment extends BaseMvpFragment<ShipmentsStaticsPresenter> implements ShipmentsStaticsContract.View, OnRefreshListener {
    @BindView(R.id.rv_content)
    RecyclerView rvContent;
    @BindView(R.id.tv_deliveryNo)
    TextView tvDeliveryNo;
    @BindView(R.id.bt_login)
    Button btLogin;
    @BindView(R.id.smart)
    SmartRefreshLayout smart;
    private String deliveryNo,originOrderNum;
    ShipmentsStaticsAdapter fullTrayInStaticsAdapter;

    public ShipmentsStaticsFragment(String entryNo,String originOrderNum) {
        this.deliveryNo = entryNo;
        this.originOrderNum=originOrderNum;
    }

    public ShipmentsStaticsFragment() {

    }

    @Override
    public ShipmentsStaticsPresenter getPresenter() {
        return new ShipmentsStaticsPresenter();
    }

    @Override
    public int getViewId() {
        return R.layout.fragment_statistics;
    }

    @Override
    public void initView() {
        smart.setEnableLoadMore(false);
        smart.setOnRefreshListener(this);
        btLogin.setText("出库完成");
        tvDeliveryNo.setText("出库单信息 " + originOrderNum);
        fullTrayInStaticsAdapter = new ShipmentsStaticsAdapter(R.layout.item_statistics, new ArrayList<>());
        rvContent.setAdapter(fullTrayInStaticsAdapter);
        smart.autoRefresh();
        // presenter.palletEntryStatistics(new EntryNoRequest(entryNo));
    }

    @Override
    public void initLinsenterner() {

    }

    @Override
    public void getData() {

    }
    /*@Override
    public void setList(List<FullTrayInStaticsBean> list) {
        fullTrayInStaticsAdapter.setNewInstance(list);
    }*/

    @OnClick(R.id.bt_login)
    public void onViewClicked() {
        AffirmDialog affirmDialog = new AffirmDialog(mContext, new AffirmDialog.OnConfrim() {
            @Override
            public void onConfrim() {
                presenter.deliveryFinish(deliveryNo);
            }
        });
        affirmDialog.show("确定出库完成？");
    }

    @Override
    public void showMessage(String msg) {
        super.showMessage(msg);
        smart.finishRefresh();
    }

    @Override
    public void onRefresh(RefreshLayout refreshLayout) {
        presenter.shipmentsStatistics(new DeliveryNoRequest(deliveryNo));
    }

    @Override
    public void setList(List<ShipmentsStaticsBean> list) {
        fullTrayInStaticsAdapter.setNewInstance(list);
        smart.finishRefresh();
    }
}
